package cn.com.nes.site.controller.workOrder;

import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.entity.vo.workOrder.RepairStationVo;
import cn.com.nes.site.service.workOrder.RepairStationService;
import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

/**
 * 客户服务 - 站点信息
 *
 * @Author: ShenWei
 * @Date: 2024/03/06/14:14
 */
@Controller
@RequestMapping("/v2/workOrder/station")
@Deprecated
public class RepairStationController {
    @Autowired
    RepairStationService stationService;

    /**
     * 查询站点列表
     */
    @RequestMapping(value = "/getRepairStations", method = RequestMethod.GET)
    @ResponseBody
    public PageData getRepairStations(RepairStationVo vo) throws Exception {
        vo.setManufactureId(vo.getUserInfo().getNes_companyId());
        return stationService.getRepairStations(vo);
    }

    /**
     * 删除站点
     */
    @RequestMapping(value = "/delRepairStation",method = RequestMethod.POST)
    @ResponseBody
    public PageData delRepairStation(@RequestBody RepairStationVo vo) throws Exception {
        if (StrUtil.isBlank(vo.getStationId())){
            PageData.error("请传入站点id:stationId");
        }
        vo.setManufactureId(vo.getUserInfo().getNes_companyId());
        return stationService.delRepairStation(vo);
    }

    /**
     * 新增/修改站点信息
     */
    @RequestMapping(value = "/saveRepairStation",method = RequestMethod.POST)
    @ResponseBody
    public PageData saveRepairStation(@RequestBody RepairStationVo vo) throws Exception {
        vo.setManufactureId(vo.getUserInfo().getNes_companyId());
        String stationId = stationService.saveRepairStation(vo);
        if (StrUtil.isNotBlank(stationId) && "-1".equals(stationId)) {
            return PageData.error("手机号已被使用");
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("stationId", stationId);
        return PageData.ok(map);
    }

}
